﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.Serialization;

public class ControlView : MonoBehaviour
{
    public float moveSpeed;
    public float zoomSpeed;

    private bool isPanning = false;
    private Vector3 lastMousePosition;

    void Update()
    {
        OnWheelZoom();
        OnMiddlePan();
    }

    void OnWheelZoom()
    {
        if (scrollLock.Acquire(MousePriority.Screen))
        {
            float scroll = Input.GetAxis("Mouse ScrollWheel");
            if (scroll != 0)
            {
                transform.Translate(Vector3.forward * scroll * zoomSpeed, Space.Self);
            }
            scrollLock.Release(MousePriority.Screen);
        }
    }

    void OnMiddlePan()
    {
        if (Input.GetMouseButtonDown(2))
        {
            isPanning = true;
            lastMousePosition = Input.mousePosition;
        }

        if (Input.GetMouseButtonUp(2))
        {
            isPanning = false;
        }

        if (isPanning)
        {
            Vector3 delta = Input.mousePosition - lastMousePosition;
            transform.Translate(-delta.x * moveSpeed * 0.01f, -delta.y * moveSpeed * 0.01f, 0, Space.World);
            lastMousePosition = Input.mousePosition;
        }
    }
}